﻿using System;

namespace Validate.Net
{
    /// <summary>
    /// 校验ip
    /// </summary>
    public class ValidateIpAttribute : ValidateRegularAttribute
    {
        private static string regularStr = @"(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))";

        public ValidateIpAttribute() : base(regularStr)
        { }

        public override bool Validate(object value, out string msg)
        {
            if (base.Validate(value, out msg))
                return true;
            else
            {
                msg = "校验ip失败";
                return false;
            }
        }
    }
}
